package rpg.engine.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;

import rpg.util.Objects;
import rpg.util.Strings;

public class Story {
    public static class Builder {
        public Builder() {
            super();
        }

        private final List<DialogInfo> chats = new ArrayList<DialogInfo>();

        public Builder chat(DialogInfo di) {
            chats.add(di);
            return this;
        }

        private String id = "";

        public Builder id(String s) {
            id = s;
            return this;
        }

        public Story build() {
            return new Story(this);
        }

        private final List<MagicArea> magicAreas = new ArrayList<MagicArea>();

        public Builder magicArea(MagicArea a) {
            magicAreas.add(a);
            return this;
        }

        private final List<GameEffect> startEffects = new ArrayList<GameEffect>();

        public Builder effect(GameEffect i) {
            Objects.requireNonNull(i, "Story.Builder.gameEffect");
            startEffects.add(i);
            return this;
        }
    }

    private Story(Builder b) {
        super();
        id = Strings.requireNonEmpty(b.id, "story.id");
        startEffects = Collections.unmodifiableList(b.startEffects);
        for (DialogInfo ci : b.chats) {
            chats.put(ci.getDialog().getId(), ci);
        }
        magicAreas.addAll(b.magicAreas);
    }

    private final String id;

    public String getId() {
        return id;
    }

    private final List<GameEffect> startEffects;

    public List<GameEffect> getStartEffects() {
        return startEffects;
    }

    private final List<MagicArea> magicAreas = new ArrayList<MagicArea>();

    public List<MagicArea> getMagicAreas() {
        return magicAreas;
    }

    private final SortedMap<String, DialogInfo> chats = new TreeMap<String, DialogInfo>();

    public SortedMap<String, DialogInfo> getChats() {
        return chats;
    }
}
